package GameDemo.FightState.AllState;

import GameDemo.Actor;
import com.EffectMgr;
import com.EventSystem.*;

import com.Log;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class AllState {

    public static BaseFightState CreateBuffState(Actor owner, ArrayList<Object> cfg) {
        String stateName = cfg.get(0).toString();
        try {
            // 获取当前类的Class对象
            Class<?> clazz = Class.forName("GameDemo.FightState.AllState." + stateName);
            // 获取构造函数
            Constructor<?> constructor = clazz.getConstructor(Actor.class, ArrayList.class);
            // 创建实例
            return (BaseFightState) constructor.newInstance(owner, cfg);
        } catch (ClassNotFoundException e) {
            Log.Error("Buff state class not found:", stateName);
        } catch (Exception e) {
            Log.Error("Failed to create buff state:", stateName, e);
        }
        return null;
    }
}

class BuffStateEx extends BaseFightState{
    Actor owner;
    public BuffStateEx(Actor owner, ArrayList<Object> cfg) {
        super(owner);
        this.owner = owner;
        Log.Debug("BuffStateEx create");
        eventReg.Register(EventType.Damage, this::OnBeDamage);
    }

    void OnBeDamage(int data)
    {
        Log.Debug("BuffStateEx OnBeDamage");
    }

    void OnDamTarget(EffectMgr.Unit target)
    {
    }
}


//比如钢背施法叠加加速
class BuffStateAdd extends BaseFightState{
    Actor owner;
    public BuffStateAdd(Actor owner, ArrayList<Object> cfg) {
        super(owner);
        this.owner = owner;
        eventReg.Register(EventType.Damage, this::OnBeDamage);
        Log.Debug("BuffStateAdd create");
    }
    public void Stack(ArrayList<Object> cfg)
    {
        Log.Debug("BuffStateAdd Stack");
    }

    void OnBeDamage(int data)
    {
    }
    
    void OnDamTarget(EffectMgr.Unit target)
    {
    }
}


class BuffStateHight extends BuffStateEx
{
    Actor owner;
    public BuffStateHight(Actor owner, ArrayList<Object> cfg) {
        //修改根据需求 调整参数
            //例如： BuffStateEx 3 表示 3 级地震
    // BuffStateHight 3,2 表示地震级别= 3+ 角色等级*2 
        super(owner, cfg);
        Log.Debug("BuffStateHight create");
    }
}

//比如暗黑2， 野蛮人， 德鲁伊 加血，只能一个生效
class AddHpState extends BaseMutexState{
    public AddHpState(Actor owner, ArrayList<Object> cfg) {
        super(owner, StateMutexType.AddHp);
        Log.Debug("AddHpState create");
    }

    @Override
    public long Priority() {
        return 0;
    }
    
    @Override
    public void OnActivate() {
        Register(EventType.GetAddHp, this::GetAddHp);
    }

    void GetAddHp(AtomicInteger data) {
        data.addAndGet(100);
    }
}